import 'package:flutter/material.dart';
import 'package:x3_component_core/utils/base_component_utils.dart';

class BaseMenuListTile extends StatelessWidget {
  final Function onPress;
  final String title;
  final Widget prefix;
  final bool isShowSuffix;
  final double height;
  const BaseMenuListTile({Key key, this.onPress, @required this.title, this.prefix, this.isShowSuffix = false})
      : height = 48,
        super(key: key);
  const BaseMenuListTile.shrinkWrap({Key key, this.onPress, @required this.title, this.prefix, this.isShowSuffix = false})
      : height = 40,
        super(key: key);
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: this.onPress,
      child: Container(
        height: this.height,
        child: Row(
          children: [
            Text(this.title ?? '', style: Theme.of(context).textTheme.bodyText2),
            Expanded(child: SizedBox()),
            _buildRightIcon(context, this.isShowSuffix),
          ],
        ),
      ),
    );
  }

  Widget _buildPrefix() {
    if (this.prefix != null) return Row(children: [this.prefix, SizedBox(width: 12)]);
    return SizedBox();
  }

  Widget _buildRightIcon(BuildContext context, bool isClickEnabled) {
    return isClickEnabled ? BaseComponentUtils.buildListViewRightIcon(context) : Text('');
  }
}
